﻿using Factory;
using Unity.AI.Navigation;
using UnityEngine;

namespace Logic
{
    public class NavMeshGenerator : MonoBehaviour
    {
        [SerializeField] private NavMeshSurface _navMeshSurface;

        private void Start() =>
            GameFactory.FloorGenerated += CreateNavMesh;

        private void CreateNavMesh()
        {
            var obj = GameObject.FindWithTag(Constants.NavMeshTag);
            obj?.TryGetComponent(out _navMeshSurface);
            if (_navMeshSurface != null)
                _navMeshSurface.BuildNavMesh();
        }
    }
}